Page({
  data: {
    angle: 0,
    result: '',
    arrows: "https://img.icons8.com/office/1600/long-arrow-up.png",
    swingInterval: null,
    a: 210,
    b: 240,
    //游戏成功区域范围，单位：度
  },

  onLoad: function () {
    this.startSwinging();
  },

  startSwinging: function () {
    console.log(this.data.a)
    let that = this;
    let angle = 0;
    let direction = 1;
    let swingInterval = setInterval(function () {
      angle += direction * 15 * getApp().globalData.NanDu;
      if (angle >= 360) {
        angle = 0;
      } else if (angle < 0) {
        angle = 360;
      }
      that.setData({ angle: angle });
    }, 100);
    this.setData({ swingInterval: swingInterval });
  },

  stopSwinging: function () {
    clearInterval(this.data.swingInterval);
    let angle = this.data.angle;
    let successRange = this.data.successRange;
    if (angle >= this.data.a && angle <= this.data.b) {
      this.setData({ 
        result: '“剁手”成功啦' ,
      });
    } else {
      this.setData({ 
        result: '“剁手”失败啦' ,
        money: getApp().globalData.money -= 298
      });
    }
    wx.showModal({
      title: '“剁手”结果',
      content: this.data.result,
      showCancel: false,
      complete: (res) => {
        if (res.confirm) {
         wx.reLaunch({
           url: '/pageC/pageC',
         }) 
        }
      }
    })
  }
});